package org.e_gold.model.crawler.livescore;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.e_gold.model.ValueObject;

import com.google.gson.annotations.Expose;

/**
 * @author Thang Nguyen
 */
@Entity
@Table(name = "country")
public class Country extends ValueObject implements Serializable, Comparable<Country>{

	private static final long	serialVersionUID	= 1L;

	@Id
	@GeneratedValue
	@Expose
	private Long id;

	@Column(name = "name")
	@Expose
	private String name;

	@Column(name = "url")
	@Expose
	private String url;

	@OneToMany(fetch = FetchType.EAGER)
	@Expose
	private Set<League> leagues = new HashSet<League>(0);

	private boolean status = false;

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public Country(){
		this("", "");
	}

	public Country(String name){
		this(name, "");
	}

	public Country(String name, String url){
		this.name = name;
		this.url = url;
	}

	@Override
	public int compareTo(Country o) {
		return name.compareTo(o.getName());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((leagues == null) ? 0 : leagues.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((url == null) ? 0 : url.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Country)) {
			return false;
		}
		Country other = (Country) obj;
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		if (url == null) {
			if (other.url != null) {
				return false;
			}
		} else if (!url.equals(other.url)) {
			return false;
		}
		return true;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<League> getLeagues() {
		return leagues;
	}

	public void setLeagues(Set<League> leagues) {
		this.leagues = leagues;
	}
}
